clear

* generate raw inputs as in actual randomization 2017
set obs 43
gen judgetype = "Bankruptcy" if _n<=9
replace judgetype = "Circuit" if inrange(_n,10,19)
replace judgetype = "District" if inrange(_n,20,36)
replace judgetype = "Magistrate" if inrange(_n,37,43)
tempfile inputs
save `inputs'

*** randomization: copied from randomization_script.do used in 2017
* forum
gen random = runiform()
sort judgetype random
by judgetype (random): gen Forum = "W" if _n<3
replace Forum = "S" if mi(Forum)
* accident state
bys judgetype Forum: egen median = median(random)
gen Accident_state = "K" if random<median
replace Accident_state = "N" if random>median
gen random2 = runiform()
sort Accident_state random2
replace Accident_state = "K" if random==median & mod(_n,2)==0
replace Accident_state = "N" if mi(Accident_state)
drop median
* sympathy
replace random = runiform() // re-randomizing to avoid any ordering effects from unequal judge type group sizes
sort Forum Accident_state random
by Forum Accident_state: egen median = median(random)
by Forum Accident_state (random): gen Sympathy = "S" if random<median
by Forum Accident_state (random): replace Sympathy = "N" if random>median
replace random2 = runiform()
sort Sympathy random2
replace Sympathy = "S" if random==median & mod(_n,2)==0
replace Sympathy = "N" if mi(Sympathy)
drop median random random2

*** re-randomizing to avoid ordering effect from prior sort on forum etc.
gen random = runiform()
sort judgetype random
drop random

*** 
